####
#
# Copyright 2007 B. Chandler Carruth
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
####
#
# ./Rakefile
#
# This file provides a basic rake-based build for RCons. Yes it is
# fairly ironical that a build tool, RCons, is being built by another
# build tool, Rake. However, Rake is very robust, and well tailored for
# easy building of Ruby projects, making it ideal here. RCons is aimed
# initially at C/C++ projects, and as such it will be some time before
# it is sufficiently robust and capable in the Ruby arena to replace
# Rake where desired. This is, of course, an eventual "bootstrap" goal.
#
####

begin
  require( 'rubygems' )
  require( 'rake/gempackagetask' )
rescue Exception
  nil
end

require( 'rake/clean' )
require( 'rake/testtask' )
require( 'rake/rdoctask' )

# Provide stderr output, as we want to preserve stdout
def pute(msg='')
  STDERR.puts( msg )
end

CURRENT_VERSION = "0.0.1"

PKG_VERSION = CURRENT_VERSION

SRC_RB = FileList.new('lib/**/*.rb', 'bin/rcons')
RDOCS = FileList.new('README',
                     'LICENSE.txt',
                     'TODO',
                     'doc/**/*.rdoc')

task :default => [:test]


# Specific Tasks

gem_spec = Gem::Specification.new do |s|
  s.name = "rcons"
  s.version = PKG_VERSION
  s.homepage = "http://rcons.sourceforge.net/"
  s.author = "Chandler Carruth"
  s.email = "chandlerc@gmail.com"
  s.summary = <<EOT
RCons is a build tool consolidating both configuration and compilation
of software projects. It leverages the Ruby language to create a fluid
environment for specifying the build process with the expressive power
of a real programming language.
EOT
  s.files = SRC_RB
  s.has_rdoc = true
  s.extra_rdoc_files = RDOCS
  s.require_path << "lib"
  s.requirements << "none"
end

Rake::GemPackageTask.new(gem_spec) do |pkg|
  pkg.need_tar_gz = true
  pkg.need_tar_bz2 = true
  pkg.need_zip = true
end

desc "Build RDoc Documentation"
rdoc = Rake::RDocTask.new('rdoc') do |rd|
  rd.rdoc_dir = 'doc/html'
  rd.template = 'html'
  rd.title = 'Ruby Software Construction'
  rd.options << '--line-numbers' <<
    '--inline-source' <<
    '--main' << 'README' <<
    '--title' << 'Ruby Software Construction'
  rd.rdoc_files.include(RDOCS)
  rd.rdoc_files.include(SRC_RB)
end

desc "Run Unit Tests"
test = Rake::TestTask.new('test') do |t|
  t.pattern = 'test/*_test.rb'
  t.verbose = true
  t.warning = true
end

# Support Tasks

desc "List all ruby files used"
task :rubyfiles do
  puts SRC_RB
end


